<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function fn1(val) {
        console.log('fn1', val);
        return val;
    }

    function fn2(val) {
        console.log('fn2', val);
        return val;
    }

    function fn3(val) {
        console.log('fn3', val);
        return val;
    }
    // fn1(1);
    // fn2(1);
    // fn3(1);

    // fn3(fn2(fn1(1)))

    // 柯里化
    function currying() {
        const list = [...arguments];
        if (list.length === 0) {
            return (val) => val;
        }
        if (list.length === 1) {
            return list[0];
        }
        return list.reduce((f1, f2) => {
            return (...args) => {
                return f2(f1(...args));
            }
        })
    }

    currying.__proto__[Symbol.toPrimitive] = () => {
        console.log('Symbol.toPrimitive');
        return 10;
    };
    // console.log(currying - 1);
    // currying();

    // currying()(1);
    // currying(fn1)(1);
    // currying(fn1, fn2)(1);
    // currying(fn1, fn2, fn3)(1);
</script>
</body>
</html>